package ${table.package}.dao.impl;

import java.util.ArrayList;
import java.util.List;

import cn.com.asb.mdms.base.dao.hibernate.BaseDAOHibernate;
import cn.com.asb.mdms.base.util.query.PartialCollection;
import cn.com.asb.mdms.base.util.query.QueryInfo;
import org.apache.commons.lang.StringUtils;
import ${table.package}.dao.${table.destinationClassName}Dao;
import ${table.package}.bo.${table.destinationClassName};

public class ${table.destinationClassName}DaoImpl extends BaseDAOHibernate implements ${table.destinationClassName}Dao {
	
	public Class<${table.destinationClassName}> getClazz() {
		return ${table.destinationClassName}.class;
	}

	public List<${table.destinationClassName}> queryByQueryInfo(QueryInfo info) {
		String hql = "from ${table.destinationClassName} as ${table.variableName} where 1=1 ";
		String countHqlHead = "select count(${table.variableName}.id) ";
		List<${table.destinationClassName}> args = new ArrayList<${table.destinationClassName}>();

//		String name = (String) info.getQueryParameters().get("name");
//		Integer canControl = (Integer) info.getQueryParameters().get(
//				"canControl");
//		Integer canSnatchMulti = (Integer) info.getQueryParameters().get(
//				"canSnatchMulti");
//		Integer canSnatchSingle = (Integer) info.getQueryParameters().get(
//				"canSnatchSingle");
//
//		Integer canView = (Integer) info.getQueryParameters().get("canView");
//		Integer canWarn = (Integer) info.getQueryParameters().get("canWarn");
//
//		if (StringUtils.isNotEmpty(name)) {
//			hql += "and ${table.variableName}.name = ? ";			
//			args.add(name);
//		}

		
		int total = ((Integer) findUniqueResult(countHqlHead + hql, args.toArray()))
				.intValue();
		List<${table.destinationClassName}> result = null;
		if (total > 0) {
			result = executeFind(hql, args.toArray());
		} else {
			result = new ArrayList<${table.destinationClassName}>();
		}
		return result;
	}

	public PartialCollection query(QueryInfo info) {
		log.error("not implemented");
		// TODO Auto-generated method stub
		return null;
	}
	


}